import { configureStore } from "@reduxjs/toolkit";
import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux";
import counterSlice from "./counter";

const store = configureStore({
  reducer: {
    counter: counterSlice,
  },
});

// state的ts类型
export type RootState = ReturnType<typeof store.getState>;
// dispatch的ts类型
export type AppDispatch = typeof store.dispatch;

// 用下面的api，为了满足ts类型
export const useAppDispatch = () => useDispatch<AppDispatch>();
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;

export default store;
